<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
	<title>服务网关管理</title>
	<link th:href="@{/js/plugin/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
	<link th:href="@{/css/materialdesignicons.min.css}" rel="stylesheet">
	<link th:href="@{/css/style.min.css}" rel="stylesheet">
	<style>
	.lyear-wrapper {
	    position: relative;
	}
	.lyear-login {
	    display: flex !important;
	    min-height: 100vh;
	    align-items: center !important;
	    justify-content: center !important;
	}
	.lyear-login:after{
	    content: '';
	    min-height: inherit;
	    font-size: 0;
	}
	.login-center {
	    background: #fff;
	    min-width: 29.25rem;
	    padding: 2.14286em 3.57143em;
	    border-radius: 3px;
	    margin: 2.85714em;
	}
	.login-header {
	    margin-bottom: 1.5rem !important;
	}
	.login-center .has-feedback.feedback-left .form-control {
	    padding-left: 38px;
	    padding-right: 12px;
	}
	.login-center .has-feedback.feedback-left .form-control-feedback {
	    left: 0;
	    right: auto;
	    width: 38px;
	    height: 38px;
	    line-height: 38px;
	    z-index: 4;
	    color: #dcdcdc;
	}
	.login-center .has-feedback.feedback-left.row .form-control-feedback {
	    left: 15px;
	}
	
	/*表单校验样式*/
	form em {
		color:#C80101;
	}
	form .error {	
		color: red;
	    border-color:red;
	}
	form .valid {
		color: black;
	}
	.form-error {
		color: red;
	    border-color:red;
	}
	.form-valid {
		color: black;
	}
	form .tooltip-inner {
	 	border:1px solid #E8343B;
	 	background-color:#FFF;
	 	color:#CA303C;
	}
	form .tooltip.top .tooltip-arrow {
	    border-top-color: #CA303C;
	}
	</style>
</head>
  
<body>
<div class="row lyear-wrapper" style="background-image: url(img/login-bg.jpg); background-size: cover;">
  <div class="lyear-login">
    <div class="login-center">
      <div class="login-header text-center">
        <a href="#"> 服务网关管理 </a>
      </div>
      <form action="#" method="post" id="form">
        <div class="form-group has-feedback feedback-left row">
          <div class="col-xs-12">
          	<input type="text" placeholder="请输入您的用户名" class="form-control" name="loginName" id="loginName" />
          	<span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
          </div>
        </div>
        <div class="form-group has-feedback feedback-left row">
          <div class="col-xs-12">          	
          	<input type="password" placeholder="请输入密码" class="form-control" id="password" name="password" />
          	<span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
          </div>
        </div>
        <div class="form-group">
          <button class="btn btn-block btn-primary" type="submit" id="login">立即登录</button>
        </div>
      </form>
      <hr>
      <footer class="col-sm-12 text-center">
        <p class="m-b-0">Copyright © 2019 . All right reserved</p>
      </footer>
    </div>
  </div>
</div>
<script type="text/javascript" th:src="@{/js/plugin/jquery/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/plugin/bootstrap/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/js/plugin/jquery/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/js/plugin/layer/layer.min.js}"></script>
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<script type="text/javascript">
$(function() {
	
	$('#form').validate({
		rules:{
			loginName: {
				required:true
			},
			password: {
				required:true,
			}
		},
		messages:{
			loginName: {
				required: '请输入您的用户名'
			},
			password: {
				required: '请输入您的密码'
			}
		},
        submitHandler:function(form){
        	var loginReq = $('#form').serializeJson();
        	login(loginReq);
        	return false;
        }
	});
	
	function login(loginReq) {
		
		var index = layer.load(1);
		
		var $promise = $.ajax({
			type: 'post', 
			url: 'login', 
			data: JSON.stringify(loginReq), 
			dataType: 'json',
			contentType: 'application/json; charset=utf-8'
		});
		
		$promise.done(function(result) {
			
			if(result.code == '0') {
				window.location.href = 'index.html';
			} else {
				layer.msg(result.msg, {icon: '5'});
			}
			
			layer.close(index);
			
		}).fail(function(xhr,status){
			layer.close(index);
			layer.msg('网络异常,请稍后重试', {icon: '5'});
		});
		
	}
	
});
</script>
</body>
</html>